using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;
using Ghasam.Business.DAO;
using Spring.Transaction.Interceptor;

namespace Ghasam.Business.Services.Impl
{
    public class AccountingService:IAccountingService
    {
        private IPaymentDao iPaymentDao;
        private IAccountingDao iAccountingDao;
        private ICustomerDao iCustomerDao;

        public IPaymentDao IPaymentDao
        {
            set{iPaymentDao = value;}
            get {return iPaymentDao; }
        }

        public ICustomerDao ICustomerDao
        {
            set { iCustomerDao = value; }
            get { return iCustomerDao; }
        }

        public IAccountingDao IAccountingDao
        {
            set { iAccountingDao = value; }
            get { return iAccountingDao; }
        }

        [Transaction(ReadOnly = false)]
        public void AccountingSaveOrUpadate(int customerId, bool isFormal, float debit, float credit, string description, DateTime accountingDate, DateTime? createDate)
        {
            Accounting accounting = new Accounting();
            accounting.AccountingDate = accountingDate;
            accounting.CreateDate = createDate;
            accounting.Debit = debit;
            accounting.Description = description;
            accounting.IsFormal = isFormal;
            //Payment payment = IPaymentDao.FindById(paymentId);
            Customer customer = ICustomerDao.FindById(customerId);
            accounting.Customer = customer;
            //accounting.Payment = payment;
            IAccountingDao.SaveOrUpdate(accounting);
        }

        public IList<Accounting> FindAccounts(int? customerId, bool isFormal, DateTime? startDate, DateTime? endDate)
        {
            return IAccountingDao.FindAccounts(customerId,isFormal,startDate,endDate);
        }
        public IList<Accounting> FindAccountsBySorting(int? customerId, bool isFormal, DateTime? startDate, DateTime? endDate, string param, bool asc)
        {
            return IAccountingDao.FindAccountsBySorting(customerId, isFormal, startDate, endDate,param,asc);
        }
    }
}
